﻿package mortal.game.view.combinedServer.item
{
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import flash.display.*;
    import flash.geom.*;
    import frEngine.pools.*;
    import frEngine.primitives.object2d.*;
    import mortal.component.gconst.*;
    import mortal.component.rotate3dModelSprite.*;
    import mortal.component.window.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.scene3D.model.data.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.view.common.*;

    public class ShowActionPlayerSp extends GSprite
    {
        private var _window:Window;
        protected var _bd:BitmapData;
        private var _rotate3d:Rotate3dModelSprite;
        protected var _rect3d:Rect3DObject;
        protected var _img2d:Img2D;
        private var _bodyPlayer:ActionPlayer;
        protected var _wid:int = 672;
        protected var _hei:int = 481;
        protected var _markX:int = 7;
        protected var _markY:int = 34;
        private var _mesh:String;
        private var _bone:String;
        private var _textTure:String;
        private var _xx:int;
        private var _yy:int;
        private var _scaleX:Number;
        private var _scaleY:Number;
        private var _scaleZ:Number;

        public function ShowActionPlayerSp()
        {
            return;
        }// end function

        public function setXYWH(param1:int, param2:int, param3:int, param4:int) : void
        {
            this._markX = param1;
            this._markY = param2;
            this._wid = param3;
            this._hei = param4;
            return;
        }// end function

        public function get window() : Window
        {
            return this._window;
        }// end function

        public function set window(param1:Window) : void
        {
            this._window = param1;
            return;
        }// end function

        public function set img2DUrl(param1:String) : void
        {
            LoaderManager.instance.load(param1, this.onBgLoadCompl);
            return;
        }// end function

        public function get top3dSp() : Sprite
        {
            return this._window.contentTopOf3DSprite;
        }// end function

        protected function init3DRect() : void
        {
            if (this._window && this._rect3d == null)
            {
                this._rect3d = Rect3DManager.instance.registerWindow(true, new Rectangle(this._markX, this._markY, this._wid, this._hei), this._window);
                Rect3DManager.instance.windowShowHander(null, this._window);
                this._rotate3d = UIFactory.getUICompoment(Rotate3dModelSprite, this._markX, this._markY, this._window.contentTopOf3DSprite);
                this._rotate3d.setSize(this._wid, this._hei);
            }
            return;
        }// end function

        protected function add3dBg() : void
        {
            if (this._rect3d)
            {
                this._img2d = new Img2D(null, this._bd, new Rectangle(0, 0, this._wid, this._hei), false);
                this._rect3d.addImg(this._img2d);
            }
            return;
        }// end function

        protected function onBgLoadCompl(param1) : void
        {
            if (isDisposed)
            {
                return;
            }
            this._bd = param1.bitmapData as BitmapData;
            this.init3DRect();
            this.init3DRect();
            this.add3dBg();
            if (this._mesh)
            {
                this.setPlayer(this._mesh, this._bone, this._textTure, this._xx, this._yy, this._scaleX, this._scaleY, this._scaleZ);
            }
            return;
        }// end function

        public function setPlayer(param1:String, param2:String, param3:String, param4:int, param5:int, param6:Number = 1, param7:Number = 1, param8:Number = 1) : void
        {
            if (this._rect3d == null)
            {
                this._mesh = param1;
                this._bone = param2;
                this._textTure = param3;
                this._xx = param4;
                this._yy = param5;
                this._scaleX = param6;
                this._scaleY = param7;
                this._scaleZ = param8;
                return;
            }
            this._mesh = null;
            if (this._rect3d && this._bodyPlayer)
            {
                this._rect3d.disposeObj3d(this._bodyPlayer);
            }
            this._bodyPlayer = FrObjectPool.getObject(ActionPlayer, this);
            this._bodyPlayer.changeAction(ActionName.Stand);
            this._bodyPlayer.hangBoneName = BoneConst.MountHangModelBone;
            this._bodyPlayer.selectEnabled = false;
            this._bodyPlayer.play();
            this._bodyPlayer.setRotation(0, 0, 0);
            this._bodyPlayer.scaleX = param6;
            this._bodyPlayer.scaleY = param7;
            this._bodyPlayer.scaleZ = param8;
            this._bodyPlayer.load(param1 + ".md5mesh", param2 + ".skeleton", param3);
            this._rect3d.addObject3d(this._bodyPlayer, param4, param5);
            this._rotate3d.model = this._bodyPlayer;
            this._bodyPlayer.name = "showAction";
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this.remove3D();
            this._window = null;
            this._mesh = null;
            this._bd = null;
            this._rotate3d = null;
            super.disposeImpl(param1);
            return;
        }// end function

        protected function remove3D() : void
        {
            if (this._rect3d)
            {
                if (this._img2d)
                {
                    this._rect3d.removeImg(this._img2d);
                    this._img2d = null;
                }
                if (this._rect3d && this._bodyPlayer)
                {
                    this._rect3d.disposeObj3d(this._bodyPlayer);
                    this._bodyPlayer = null;
                }
                Rect3DManager.instance.disposeRect3d(this._rect3d);
                this._rect3d = null;
            }
            return;
        }// end function

        public function get bodyPlayer() : ActionPlayer
        {
            return this._bodyPlayer;
        }// end function

        public function get bd() : BitmapData
        {
            return this._bd;
        }// end function

        public function set bd(param1:BitmapData) : void
        {
            this._bd = param1;
            return;
        }// end function

        public function set bodyPlayer(param1:ActionPlayer) : void
        {
            this._bodyPlayer = param1;
            return;
        }// end function

    }
}
